package com.jintoufs.service.baseinfo.impl;

import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.baseinfo.CoinDAO;
import com.jintoufs.domain.baseinfo.Coin;
import com.jintoufs.service.baseinfo.CoinService;
import org.cosmos.modules.web.msg.AjaxMsg;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xiaoemo
 */
@Repository
public class CoinServiceImpl implements CoinService {
    @Resource
    private CoinDAO coinDAO;

    @Override
    public AjaxMsg insert(Coin Coin) {
        AjaxMsg ajaxMsg=new AjaxMsg();
        Map map=new HashMap();
        map.put("code",Coin.getCode());
        List cons =coinDAO.queryByParams(map);
        if(cons.isEmpty()){
            coinDAO.insert(Coin);
            ajaxMsg.setCode(AjaxMsg.SUCCESS);
        }else {
            ajaxMsg.setCode(AjaxMsg.FAILURE);
            ajaxMsg.setMessage("对象已经存在");
        }
        return ajaxMsg;
    }

    @Override
    public void updateByPrimaryKey(Coin Coin) {
        coinDAO.updateByPrimaryKey(Coin);
    }

    @Override
    public void deleteByPrimaryKey(Integer id) {
        coinDAO.deleteByPrimaryKey(id);
    }

    @Override
    public List<Map<String, Object>> getByFilter(QueryFilters filters) {
        return coinDAO.getByFilter(filters);
    }

    @Override
    public List<Map<String, Object>> queryByParams(Map<String, Object> params) {
        return coinDAO.queryByParams(params);
    }
    @Override
    public List<Map<String, Object>> querySiteCoinByParams(Map<String, Object> params) {
        return coinDAO.querySiteCoinByParams(params);
    }

    @Override
    public Coin selectByPrimaryKey(Integer id) {
        return coinDAO.selectByPrimaryKey(id);
    }
}
